﻿/*
 * FileName: Team.cs
 * Module: Core
 * Author: Gourav Das
 * Created: 04/2011
 * Modifications:
 * Copyright: Gourav Das, 2011
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using _22yards.Core;

namespace _22yards.Core
{
    public class Team
    {
        public short getRegionIDFromTeamID()
        {
            return (short)(TeamNumber / 1000000);
        }

        public string getRegionNameFromTeamID()
        {
            int regionID = getRegionIDFromTeamID();

            XmlTextReader xmlReader = new XmlTextReader(@"..\..\Teams\Teams.xml");
            while (xmlReader.Read())
            {
                switch (xmlReader.NodeType)
                {
                    case XmlNodeType.Element:
                        if (xmlReader.Name == "REGION")
                        {
                            string IDfromXML=xmlReader.GetAttribute("ID");
                            if (IDfromXML == regionID.ToString())
                                return xmlReader.GetAttribute("name");
                        }
                        break;
                }
            }
            return "INVALID REGION ID";
        }

        public short getCountryIDFromTeamID()
        {
            int tmp = TeamNumber / 10000;
            return (short)(tmp%100);
        }

        public string getCountryNameFromTeamID()
        {
            int countryID = getCountryIDFromTeamID();

            XmlTextReader xmlReader = new XmlTextReader(@"..\..\Teams\Teams.xml");
            while (xmlReader.Read())
            {
                switch (xmlReader.NodeType)
                {
                    case XmlNodeType.Element:
                        if (xmlReader.Name == "COUNTRY")
                        {
                            string IDfromXML = xmlReader.GetAttribute("ID");
                            if (IDfromXML == countryID.ToString())
                                return xmlReader.GetAttribute("name");
                        }
                        break;
                }
            }
            return "INVALID COUNTRY ID";
        }
        
        public int getTeamTypeIDFromTeamID()
        {
            int tmp = TeamNumber / 100;
            return (short)(tmp % 10000);
        }

        public string getTeamTypeNameFromTeamID()
        {
            int teamTypeID = getTeamTypeIDFromTeamID();

            XmlTextReader xmlReader = new XmlTextReader(@"..\..\Teams\Teams.xml");
            while (xmlReader.Read())
            {
                switch (xmlReader.NodeType)
                {
                    case XmlNodeType.Element:
                        if (xmlReader.Name == "TYPE")
                        {
                            string IDfromXML = xmlReader.GetAttribute("ID");
                            if (IDfromXML == teamTypeID.ToString())
                                return xmlReader.GetAttribute("name");
                        }
                        break;
                }
            }
            return "INVALID TYPE ID";

        }

        public static string getTeamNamefromTeamID(int CompleteTeamID)
        {
            XmlTextReader xmlReader = new XmlTextReader(@"..\..\Teams\Teams.xml");
            while (xmlReader.Read())
            {
                switch (xmlReader.NodeType)
                {
                    case XmlNodeType.Element:
                        if (xmlReader.Name == "TEAM")
                        {
                            string IDfromXML = xmlReader.GetAttribute("ID");
                            if (IDfromXML == CompleteTeamID.ToString())
                                return xmlReader.GetAttribute("name");
                        }
                        break;
                }
            }
            return "INVALID TEAM ID";

        }


        public decimal NetMoney { get; set; }
        public int TeamNumber { get; set; }
        public string TeamName { get; set; }
        public string TeamShortName { get; set; }
        public List<cPlayer> players;
        public bool TossWinner { get; set; }
        public bool IsUserSelected { get; set; }

        public int TestMatchesPlayed { get; set; }
        public int ODIMatchesPlayed { get; set; }
        public int T20MatchesPlayed { get; set; }
        public int DOM5DAYMatchesPlayed { get; set; }
        public int DOM4DAYMatchesPlayed { get; set; }
        public int DOMODIMatchesPlayed { get; set; }
        public int DOMT20MatchesPlayed { get; set; }
        public int StreetMatchesPlayed { get; set; }
        public int CustomMatchesPlayed { get; set; }
        public int ParkMatchesPlayed { get; set; }

        public int TestMatchesWon { get; set; }
        public int ODIMatchesWon { get; set; }
        public int T20MatchesWon { get; set; }
        public int DOM5DAYMatchesWon { get; set; }
        public int DOM4DAYMatchesWon { get; set; }
        public int DOMODIMatchesWon { get; set; }
        public int DOMT20MatchesWon { get; set; }
        public int StreetMatchesWon { get; set; }
        public int CustomMatchesWon { get; set; }
        public int ParkMatchesWon { get; set; }

        public int TestMatchesNoResult { get; set; }
        public int ODIMatchesNoResult { get; set; }
        public int T20MatchesNoResult { get; set; }
        public int DOM5DAYMatchesNoResult { get; set; }
        public int DOM4DAYMatchesNoResult { get; set; }
        public int DOMODIMatchesNoResult { get; set; }
        public int DOMT20MatchesNoResult { get; set; }
        public int StreetMatchesNoResult { get; set; }
        public int CustomMatchesNoResult { get; set; }
        public int ParkMatchesNoResult { get; set; }

        public int TestMatchesTie { get; set; }
        public int ODIMatchesTie { get; set; }
        public int T20MatchesTie { get; set; }
        public int DOM5DAYMatchesTie { get; set; }
        public int DOM4DAYMatchesTie { get; set; }
        public int DOMODIMatchesTie { get; set; }
        public int DOMT20MatchesTie { get; set; }
        public int StreetMatchesTie { get; set; }
        public int CustomMatchesTie { get; set; }
        public int ParkMatchesTie { get; set; }

        public int TestMatchesTournamentsWon { get; set; }
        public int ODIMatchesTournamentsWon { get; set; }
        public int T20MatchesTournamentsWon { get; set; }
        public int DOM5DAYMatchesTournamentsWon { get; set; }
        public int DOM4DAYMatchesTournamentsWon { get; set; }
        public int DOMODIMatchesTournamentsWon { get; set; }
        public int DOMT20MatchesTournamentsWon { get; set; }
        public int StreetMatchesTournamentsWon { get; set; }
        public int CustomMatchesTournamentsWon { get; set; }
        public int ParkMatchesTournamentsWon { get; set; }

        public int TestRanking { get; set; }
        public int ODIRanking { get; set; }
        public int T20Ranking { get; set; }
        public int DOMRanking { get; set; }
        public int StreetRanking { get; set; }
        public int ParkRanking { get; set; }

        public short UDRSReviewed { get; set; }
        public short UDRSSuccessful { get; set; }

        public bool StatsUpdatable { get; set; }
        public short FinedSlowOverRate { get; set; }

        private bool currentTeamBatting = false;
        private bool firstBatting = false;

        public bool CurrentTeamBatting 
        { 
            get
            {
                return currentTeamBatting;
            } 
            set
            {
                currentTeamBatting = value;
            }
        }
        public bool FirstBatting 
        {
            get
            {
                return firstBatting;
            }
            set
            {
                firstBatting = value;
                currentTeamBatting = value;
            }
        }

        /// <summary>
        /// Loads the intl players from XML, given a specific Region and Country
        /// </summary>
        /// <param name="_team">The _team.</param>
        /// <param name="regionID">The region ID.</param>
        /// <param name="CountryID">The country ID.</param>
        public static void LoadIntlPlayersFromXML(ref Team _team,int regionID, int CountryID)
        {
            XmlTextReader xmlReader;
            xmlReader = new XmlTextReader(@"22yardsContent\Core\Players\Players.xml");
            while (xmlReader.Read())
            {
                switch (xmlReader.NodeType)
                {
                    case XmlNodeType.Element:
                        if (xmlReader.Name == "REGION")
                        {
                            if (xmlReader.GetAttribute("ID") == regionID.ToString())
                            {
                                while (xmlReader.Read())
                                {
                                    if (xmlReader.Name == "COUNTRY" && xmlReader.NodeType == XmlNodeType.Element)
                                    {
                                        if (xmlReader.GetAttribute("ID") == CountryID.ToString())
                                        {
                                            while (xmlReader.Read())
                                            {
                                                if (xmlReader.Name == "COUNTRY" && xmlReader.NodeType == XmlNodeType.Element)
                                                    break;
                                                if (xmlReader.Name == "TYPE" && xmlReader.NodeType == XmlNodeType.Element)
                                                {
                                                    if (Convert.ToInt32(xmlReader.GetAttribute("ID")) == 10)
                                                    {
                                                        
                                                        while (xmlReader.Read() && (xmlReader.Name != "TYPE" || xmlReader.NodeType!=XmlNodeType.EndElement))
                                                        {
                                                            
                                                            if (xmlReader.Name == "PLAYER" && xmlReader.NodeType == XmlNodeType.Element)
                                                            {
                                                                cPlayer tmpPlayer = new cPlayer(DateTime.MinValue);
                                                                tmpPlayer.PlayerID = Convert.ToInt32(xmlReader.GetAttribute("ID"));
                                                                tmpPlayer.Name = xmlReader.GetAttribute("name");
                                                                try
                                                                {
                                                                    tmpPlayer.DateOfBirth = Convert.ToDateTime(xmlReader.GetAttribute("DateOfBirth"));
                                                                }
                                                                catch
                                                                {
                                                                
                                                                }
                                                                tmpPlayer.NetMoney = Convert.ToDecimal(xmlReader.GetAttribute("NetMoney"));
                                                                tmpPlayer.IsUpdatable = Convert.ToBoolean(xmlReader.GetAttribute("IsUpdatable"));
                                                                tmpPlayer.InPlaying11 = Convert.ToBoolean(xmlReader.GetAttribute("InPlaying11"));
                                                                tmpPlayer.Is12thMan = Convert.ToBoolean(xmlReader.GetAttribute("Is12thMan"));
                                                                tmpPlayer.IsWicketKeeper = Convert.ToBoolean(xmlReader.GetAttribute("IsWicketkeeper"));
                                                                tmpPlayer.InSquadOf15 = Convert.ToBoolean(xmlReader.GetAttribute("InSquadOf15"));
                                                                tmpPlayer.Volatility = Convert.ToInt16(xmlReader.GetAttribute("Volatility"));

                                                                while (xmlReader.Read() && (xmlReader.Name != "PLAYER" || xmlReader.NodeType != XmlNodeType.EndElement))
                                                                {
                                                                    while (xmlReader.Read() && (xmlReader.Name != "BATTING"))
                                                                    {
                                                                        break;
                                                                    }
                                                                    if (xmlReader.Name == "BATTING" && xmlReader.NodeType == XmlNodeType.Element)
                                                                    {
                                                                        tmpPlayer.BattingSkillPoints = Convert.ToInt16(xmlReader.GetAttribute("SkillPoints"));
                                                                        tmpPlayer.FavouriteBattingRegion = Convert.ToInt16(xmlReader.GetAttribute("FavBattingRegion"));
                                                                        tmpPlayer.FavouriteBattingShot = Convert.ToInt16(xmlReader.GetAttribute("FavBattingShot"));
                                                                        tmpPlayer.Is12thMan = Convert.ToBoolean(xmlReader.GetAttribute("IsOnStrike"));
                                                                        tmpPlayer.IsRightHandedBatsman = Convert.ToBoolean(xmlReader.GetAttribute("IsRightHandedBatsman"));
                                                                        tmpPlayer.SeriesBattingConfidence = Convert.ToInt16(xmlReader.GetAttribute("SeriesBattingConfidence"));
                                                                        tmpPlayer.CareerBattingAura = Convert.ToInt16(xmlReader.GetAttribute("CareerBattingAura"));
                                                                        tmpPlayer.CurrentBattingConfidence = Convert.ToInt16(xmlReader.GetAttribute("CurrentBattingConfidence"));
                                                                        tmpPlayer.BatsmanSettledOnPitch = Convert.ToInt16(xmlReader.GetAttribute("BatsmanSettledOnPitch"));
                                                                        tmpPlayer.SuperAgressive = Convert.ToBoolean(xmlReader.GetAttribute("SuperAgressive"));
                                                                        
                                                                    }

                                                                    while (xmlReader.Read() && (xmlReader.Name != "BOWLING"))
                                                                    {
                                                                        break;
                                                                    }


                                                                    if (xmlReader.Name == "BOWLING" && xmlReader.NodeType == XmlNodeType.Element)
                                                                    {
                                                                        tmpPlayer.BowlingSkillPoints = Convert.ToInt16(xmlReader.GetAttribute("SkillPoints"));
                                                                        //tmpPlayer.FavouriteBowlingRegion = Convert.ToInt16(xmlReader.GetAttribute("FavouriteBowlingRegion"));
                                                                        tmpPlayer.FastBowlingPoints = Convert.ToInt16(xmlReader.GetAttribute("FastBowlingPoints"));
                                                                        tmpPlayer.SpinBowlingPoints = Convert.ToInt16(xmlReader.GetAttribute("SpinBowlingPoints"));
                                                                        tmpPlayer.BowlerType = Convert.ToInt16(xmlReader.GetAttribute("BowlerType"));
                                                                        tmpPlayer.BowlingRunupLength = Convert.ToInt16(xmlReader.GetAttribute("BowlingRunupLength"));
                                                                        tmpPlayer.BowlingRunupAngle = Convert.ToInt16(xmlReader.GetAttribute("BowlingRunupAngle"));
                                                                        tmpPlayer.IsRightHandedBowler = Convert.ToBoolean(xmlReader.GetAttribute("IsRightHandedBowler"));
                                                                        tmpPlayer.CareerBowlingAura = Convert.ToInt16(xmlReader.GetAttribute("CareerBowlingAura"));
                                                                        tmpPlayer.SeriesBowlingConfidence = Convert.ToInt16(xmlReader.GetAttribute("SeriesBowlingConfidence"));
                                                                        tmpPlayer.CurrentBowlingConfidence = Convert.ToInt16(xmlReader.GetAttribute("CurrentBowlingConfidence"));
                                                                        tmpPlayer.UpperBowlingSpeedLimit = Convert.ToSingle(xmlReader.GetAttribute("UpperBowlingSpeedLimit"));
                                                                        
                                                                    }

                                                                    while (xmlReader.Read() && (xmlReader.Name != "FIELDING"))
                                                                    {
                                                                        break;
                                                                    }
                                                                    if (xmlReader.Name == "FIELDING" && xmlReader.NodeType == XmlNodeType.Element)
                                                                    {
                                                                        tmpPlayer.FieldingSkillPoints = Convert.ToInt16(xmlReader.GetAttribute("SkillPoints"));
                                                                        tmpPlayer.FavouriteFieldingPosition = Convert.ToInt32(xmlReader.GetAttribute("FavouriteFieldingPosition"));
                                                                        tmpPlayer.DivingFactor = Convert.ToInt16(xmlReader.GetAttribute("DivingFactor"));
                                                                        tmpPlayer.IsRightHandedFielder = Convert.ToBoolean(xmlReader.GetAttribute("IsRightHandedFielder"));
                                                                        tmpPlayer.CareerFieldingAura = Convert.ToInt16(xmlReader.GetAttribute("CareerFieldingAura"));
                                                                        tmpPlayer.SeriesFieldingConfidence = Convert.ToInt16(xmlReader.GetAttribute("SeriesFieldingConfidence"));
                                                                        tmpPlayer.CurrentFieldingConfidence = Convert.ToInt16(xmlReader.GetAttribute("CurrentFieldingConfidence"));
                                                                        
                                                                    }

                                                                    while (xmlReader.Read() && (xmlReader.Name != "GENERAL"))
                                                                    {
                                                                        break;
                                                                    }
                                                                    if (xmlReader.Name == "GENERAL" && xmlReader.NodeType == XmlNodeType.Element)
                                                                    {
                                                                        tmpPlayer.InjuryProne = Convert.ToBoolean(xmlReader.GetAttribute("InjuryProne"));
                                                                        tmpPlayer.LevelOfInjury = Convert.ToInt16(xmlReader.GetAttribute("LevelOfInjury"));
                                                                        tmpPlayer.NumInjured = Convert.ToInt16(xmlReader.GetAttribute("NumInjured"));
                                                                        tmpPlayer.Stamina = Convert.ToInt16(xmlReader.GetAttribute("Stamina"));
                                                                        tmpPlayer.Strength = Convert.ToInt16(xmlReader.GetAttribute("Strength"));
                                                                        tmpPlayer.InjuryLength = Convert.ToInt16(xmlReader.GetAttribute("InjuryLength"));
                                                                        
                                                                    }

                                                                    while (xmlReader.Read() && (xmlReader.Name != "TEST"))
                                                                    {
                                                                        break;
                                                                    }
                                                                    if (xmlReader.Name == "TEST" && xmlReader.NodeType == XmlNodeType.Element)
                                                                    {
                                                                        tmpPlayer.NumTestMatches = Convert.ToInt16(xmlReader.GetAttribute("Matches"));
                                                                        tmpPlayer.NumTestInnings = Convert.ToInt16(xmlReader.GetAttribute("Innings"));
                                                                        tmpPlayer.NumTestNotOuts = Convert.ToInt16(xmlReader.GetAttribute("NotOut"));
                                                                        tmpPlayer.TestRanking = Convert.ToInt16(xmlReader.GetAttribute("Ranking"));
                                                                        try
                                                                        {
                                                                            tmpPlayer.FirstTestMatch = Convert.ToDateTime(xmlReader.GetAttribute("FirstMatch"));
                                                                        }
                                                                        catch
                                                                        { }
                                                                        tmpPlayer.TestCareerRuns = Convert.ToInt16(xmlReader.GetAttribute("Runs"));
                                                                        tmpPlayer.TestCareerCenturies = Convert.ToInt16(xmlReader.GetAttribute("Centuries"));
                                                                        tmpPlayer.TestCareerHalfCenturies = Convert.ToInt16(xmlReader.GetAttribute("Fifties"));
                                                                        tmpPlayer.TestCareerHighestScore = Convert.ToInt16(xmlReader.GetAttribute("HS"));
                                                                        tmpPlayer.TestCareerBattingAvg = Convert.ToDecimal(xmlReader.GetAttribute("CareerAvg"));
                                                                        tmpPlayer.TestCareerBattingSR = Convert.ToDecimal(xmlReader.GetAttribute("CareerBattingSR"));
                                                                        tmpPlayer.TestCareerOversBowled = Convert.ToDecimal(xmlReader.GetAttribute("OversBowled"));
                                                                        tmpPlayer.TestCareerWickets = Convert.ToInt16(xmlReader.GetAttribute("Wickets"));
                                                                        tmpPlayer.TestCareerFiveWicketHaul = Convert.ToInt16(xmlReader.GetAttribute("FiveWickets"));
                                                                        tmpPlayer.TestCareerTenWicketHaul = Convert.ToInt16(xmlReader.GetAttribute("TenWickets"));
                                                                        tmpPlayer.TestCareerBestBowlingFigue = Convert.ToDecimal(xmlReader.GetAttribute("BestBowling"));
                                                                        tmpPlayer.TestCareerBowlingAvg = Convert.ToDecimal(xmlReader.GetAttribute("CareerBowlingAvg"));
                                                                        tmpPlayer.TestCareerBowlingSR = Convert.ToDecimal(xmlReader.GetAttribute("CareerBowlingSR"));
                                                                        tmpPlayer.TestCareerCatches = Convert.ToInt16(xmlReader.GetAttribute("Catches"));



                                                                    }

                                                                    while (xmlReader.Read() && (xmlReader.Name != "ODI"))
                                                                    {
                                                                        break;
                                                                    }

                                                                    if (xmlReader.Name == "ODI" && xmlReader.NodeType == XmlNodeType.Element)
                                                                    {
                                                                        tmpPlayer.Num5050Matches = Convert.ToInt16(xmlReader.GetAttribute("Matches"));
                                                                        tmpPlayer.Num5050Innings = Convert.ToInt16(xmlReader.GetAttribute("Innings"));
                                                                        tmpPlayer.Num5050NotOuts = Convert.ToInt16(xmlReader.GetAttribute("NotOut"));
                                                                        tmpPlayer.ODIRanking = Convert.ToInt16(xmlReader.GetAttribute("Ranking"));
                                                                        try
                                                                        {
                                                                            tmpPlayer.First5050Match = Convert.ToDateTime(xmlReader.GetAttribute("FirstMatch"));
                                                                        }
                                                                        catch { }
                                                                        tmpPlayer.ODICareerRuns = Convert.ToInt16(xmlReader.GetAttribute("Runs"));
                                                                        tmpPlayer.ODICareerCenturies = Convert.ToInt16(xmlReader.GetAttribute("Centuries"));
                                                                        tmpPlayer.ODICareerHalfCenturies = Convert.ToInt16(xmlReader.GetAttribute("Fifties"));
                                                                        tmpPlayer.ODICareerHighestScore = Convert.ToInt16(xmlReader.GetAttribute("HS"));
                                                                        tmpPlayer.ODICareerBattingAvg = Convert.ToDecimal(xmlReader.GetAttribute("CareerAvg"));
                                                                        tmpPlayer.ODICareerBattingSR = Convert.ToDecimal(xmlReader.GetAttribute("CareerBattingSR"));
                                                                        tmpPlayer.ODICareerOversBowled = Convert.ToDecimal(xmlReader.GetAttribute("OversBowled"));
                                                                        tmpPlayer.ODICareerWickets = Convert.ToInt16(xmlReader.GetAttribute("Wickets"));
                                                                        tmpPlayer.ODICareerFiveWicketHaul = Convert.ToInt16(xmlReader.GetAttribute("FiveWickets"));
                                                                        tmpPlayer.ODICareerTenWicketHaul = Convert.ToInt16(xmlReader.GetAttribute("TenWickets"));
                                                                        tmpPlayer.ODICareerBestBowlingFigue = Convert.ToDecimal(xmlReader.GetAttribute("BestBowling"));
                                                                        tmpPlayer.ODICareerBowlingAvg = Convert.ToDecimal(xmlReader.GetAttribute("CareerBowlingAvg"));
                                                                        tmpPlayer.ODICareerBowlingSR = Convert.ToDecimal(xmlReader.GetAttribute("CareerBowlingSR"));
                                                                        tmpPlayer.ODICareerCatches = Convert.ToInt16(xmlReader.GetAttribute("Catches"));
                                                                    }

                                                                    while (xmlReader.Read() && (xmlReader.Name != "T20"))
                                                                    {
                                                                        break;
                                                                    }
                                                                    if (xmlReader.Name == "T20" && xmlReader.NodeType == XmlNodeType.Element)
                                                                    {
                                                                        tmpPlayer.NumT20Matches = Convert.ToInt16(xmlReader.GetAttribute("Matches"));
                                                                        tmpPlayer.NumT20Innings = Convert.ToInt16(xmlReader.GetAttribute("Innings"));
                                                                        tmpPlayer.NumT20NotOuts = Convert.ToInt16(xmlReader.GetAttribute("NotOut"));
                                                                        tmpPlayer.T20Ranking = Convert.ToInt16(xmlReader.GetAttribute("Ranking"));
                                                                        try
                                                                        {
                                                                            tmpPlayer.FirstT20Match = Convert.ToDateTime(xmlReader.GetAttribute("FirstMatch"));
                                                                        }
                                                                        catch { }
                                                                        tmpPlayer.T20CareerRuns = Convert.ToInt16(xmlReader.GetAttribute("Runs"));
                                                                        tmpPlayer.T20CareerCenturies = Convert.ToInt16(xmlReader.GetAttribute("Centuries"));
                                                                        tmpPlayer.T20CareerHalfCenturies = Convert.ToInt16(xmlReader.GetAttribute("Fifties"));
                                                                        tmpPlayer.T20CareerHighestScore = Convert.ToInt16(xmlReader.GetAttribute("HS"));
                                                                        tmpPlayer.T20CareerBattingAvg = Convert.ToDecimal(xmlReader.GetAttribute("CareerAvg"));
                                                                        tmpPlayer.T20CareerBattingSR = Convert.ToDecimal(xmlReader.GetAttribute("CareerBattingSR"));
                                                                        tmpPlayer.T20CareerOversBowled = Convert.ToDecimal(xmlReader.GetAttribute("OversBowled"));
                                                                        tmpPlayer.T20CareerWickets = Convert.ToInt16(xmlReader.GetAttribute("Wickets"));
                                                                        tmpPlayer.T20CareerFiveWicketHaul = Convert.ToInt16(xmlReader.GetAttribute("FiveWickets"));
                                                                        tmpPlayer.T20CareerTenWicketHaul = Convert.ToInt16(xmlReader.GetAttribute("TenWickets"));
                                                                        tmpPlayer.T20CareerBestBowlingFigue = Convert.ToDecimal(xmlReader.GetAttribute("BestBowling"));
                                                                        tmpPlayer.T20CareerBowlingAvg = Convert.ToDecimal(xmlReader.GetAttribute("CareerBowlingAvg"));
                                                                        tmpPlayer.T20CareerBowlingSR = Convert.ToDecimal(xmlReader.GetAttribute("CareerBowlingSR"));
                                                                        tmpPlayer.T20CareerCatches = Convert.ToInt16(xmlReader.GetAttribute("Catches"));
                                                                    }

                                                                    while (xmlReader.Read() && (xmlReader.Name != "DOM5DAY"))
                                                                    {
                                                                        break;
                                                                    }
                                                                    if (xmlReader.Name == "DOM5DAY" && xmlReader.NodeType == XmlNodeType.Element)
                                                                    {
                                                                        tmpPlayer.NumFirstClass5DayMatches = Convert.ToInt16(xmlReader.GetAttribute("Matches"));
                                                                        tmpPlayer.NumFirstClass5DayInnings = Convert.ToInt16(xmlReader.GetAttribute("Innings"));
                                                                        tmpPlayer.NumFirstClass5DayNotOuts = Convert.ToInt16(xmlReader.GetAttribute("NotOut"));
                                                                        tmpPlayer.DomesticTestRanking = Convert.ToInt16(xmlReader.GetAttribute("Ranking"));
                                                                        try
                                                                        {
                                                                            tmpPlayer.FirstDOM5DayMatch = Convert.ToDateTime(xmlReader.GetAttribute("FirstMatch"));
                                                                        }
                                                                        catch { }
                                                                        tmpPlayer.DOM5DAYCareerRuns = Convert.ToInt16(xmlReader.GetAttribute("Runs"));
                                                                        tmpPlayer.DOM5DAYCareerCenturies = Convert.ToInt16(xmlReader.GetAttribute("Centuries"));
                                                                        tmpPlayer.DOM5DAYCareerHalfCenturies = Convert.ToInt16(xmlReader.GetAttribute("Fifties"));
                                                                        tmpPlayer.DOM5DAYCareerHighestScore = Convert.ToInt16(xmlReader.GetAttribute("HS"));
                                                                        tmpPlayer.DOM5DAYCareerBattingAvg = Convert.ToDecimal(xmlReader.GetAttribute("CareerAvg"));
                                                                        tmpPlayer.DOM5DAYCareerBattingSR = Convert.ToDecimal(xmlReader.GetAttribute("CareerBattingSR"));
                                                                        tmpPlayer.DOM5DAYCareerOversBowled = Convert.ToDecimal(xmlReader.GetAttribute("OversBowled"));
                                                                        tmpPlayer.DOM5DAYCareerWickets = Convert.ToInt16(xmlReader.GetAttribute("Wickets"));
                                                                        tmpPlayer.DOM5DAYCareerFiveWicketHaul = Convert.ToInt16(xmlReader.GetAttribute("FiveWickets"));
                                                                        tmpPlayer.DOM5DAYCareerTenWicketHaul = Convert.ToInt16(xmlReader.GetAttribute("TenWickets"));
                                                                        tmpPlayer.DOM5DAYCareerBestBowlingFigue = Convert.ToDecimal(xmlReader.GetAttribute("BestBowling"));
                                                                        tmpPlayer.DOM5DAYCareerBowlingAvg = Convert.ToDecimal(xmlReader.GetAttribute("CareerBowlingAvg"));
                                                                        tmpPlayer.DOM5DAYCareerBowlingSR = Convert.ToDecimal(xmlReader.GetAttribute("CareerBowlingSR"));
                                                                        tmpPlayer.DOM5DAYCareerCatches = Convert.ToInt16(xmlReader.GetAttribute("Catches"));
                                                                    }

                                                                    while (xmlReader.Read() && (xmlReader.Name != "DOM4DAY"))
                                                                    {
                                                                        break;
                                                                    }
                                                                    if (xmlReader.Name == "DOM4DAY" && xmlReader.NodeType == XmlNodeType.Element)
                                                                    {
                                                                        tmpPlayer.NumFirstClass4DayMatches = Convert.ToInt16(xmlReader.GetAttribute("Matches"));
                                                                        tmpPlayer.NumFirstClass4DayInnings = Convert.ToInt16(xmlReader.GetAttribute("Innings"));
                                                                        tmpPlayer.NumFirstClass4DayNotOuts = Convert.ToInt16(xmlReader.GetAttribute("NotOut"));
                                                                        tmpPlayer.DomesticTestRanking = Convert.ToInt16(xmlReader.GetAttribute("Ranking"));
                                                                        try
                                                                        {
                                                                            tmpPlayer.FirstDOM4DayMatch = Convert.ToDateTime(xmlReader.GetAttribute("FirstMatch"));
                                                                        }
                                                                        catch { }
                                                                        tmpPlayer.DOM4DAYCareerRuns = Convert.ToInt16(xmlReader.GetAttribute("Runs"));
                                                                        tmpPlayer.DOM4DAYCareerCenturies = Convert.ToInt16(xmlReader.GetAttribute("Centuries"));
                                                                        tmpPlayer.DOM4DAYCareerHalfCenturies = Convert.ToInt16(xmlReader.GetAttribute("Fifties"));
                                                                        tmpPlayer.DOM4DAYCareerHighestScore = Convert.ToInt16(xmlReader.GetAttribute("HS"));
                                                                        tmpPlayer.DOM4DAYCareerBattingAvg = Convert.ToDecimal(xmlReader.GetAttribute("CareerAvg"));
                                                                        tmpPlayer.DOM4DAYCareerBattingSR = Convert.ToDecimal(xmlReader.GetAttribute("CareerBattingSR"));
                                                                        tmpPlayer.DOM4DAYCareerOversBowled = Convert.ToDecimal(xmlReader.GetAttribute("OversBowled"));
                                                                        tmpPlayer.DOM4DAYCareerWickets = Convert.ToInt16(xmlReader.GetAttribute("Wickets"));
                                                                        tmpPlayer.DOM4DAYCareerFiveWicketHaul = Convert.ToInt16(xmlReader.GetAttribute("FiveWickets"));
                                                                        tmpPlayer.DOM4DAYCareerTenWicketHaul = Convert.ToInt16(xmlReader.GetAttribute("TenWickets"));
                                                                        tmpPlayer.DOM4DAYCareerBestBowlingFigue = Convert.ToDecimal(xmlReader.GetAttribute("BestBowling"));
                                                                        tmpPlayer.DOM4DAYCareerBowlingAvg = Convert.ToDecimal(xmlReader.GetAttribute("CareerBowlingAvg"));
                                                                        tmpPlayer.DOM4DAYCareerBowlingSR = Convert.ToDecimal(xmlReader.GetAttribute("CareerBowlingSR"));
                                                                        tmpPlayer.DOM4DAYCareerCatches = Convert.ToInt16(xmlReader.GetAttribute("Catches"));
                                                                    }

                                                                    while (xmlReader.Read() && (xmlReader.Name != "CUSTOM"))
                                                                    {
                                                                        break;
                                                                    }
                                                                    if (xmlReader.Name == "CUSTOM" && xmlReader.NodeType == XmlNodeType.Element)
                                                                    {
                                                                        tmpPlayer.NumCustomMatches = Convert.ToInt16(xmlReader.GetAttribute("Matches"));
                                                                        tmpPlayer.NumCustomInnings = Convert.ToInt16(xmlReader.GetAttribute("Innings"));
                                                                        tmpPlayer.NumCustomNotOuts = Convert.ToInt16(xmlReader.GetAttribute("NotOut"));
                                                                        tmpPlayer.CustomRanking = Convert.ToInt16(xmlReader.GetAttribute("Ranking"));
                                                                        try
                                                                        {
                                                                            tmpPlayer.FirstCustomMatch = Convert.ToDateTime(xmlReader.GetAttribute("FirstMatch"));
                                                                        }
                                                                        catch { }
                                                                        tmpPlayer.CustomCareerRuns = Convert.ToInt16(xmlReader.GetAttribute("Runs"));
                                                                        tmpPlayer.CustomCareerCenturies = Convert.ToInt16(xmlReader.GetAttribute("Centuries"));
                                                                        tmpPlayer.CustomCareerHalfCenturies = Convert.ToInt16(xmlReader.GetAttribute("Fifties"));
                                                                        tmpPlayer.CustomCareerHighestScore = Convert.ToInt16(xmlReader.GetAttribute("HS"));
                                                                        tmpPlayer.CustomCareerBattingAvg = Convert.ToDecimal(xmlReader.GetAttribute("CareerAvg"));
                                                                        tmpPlayer.CustomCareerBattingSR = Convert.ToDecimal(xmlReader.GetAttribute("CareerBattingSR"));
                                                                        tmpPlayer.CustomCareerOversBowled = Convert.ToDecimal(xmlReader.GetAttribute("OversBowled"));
                                                                        tmpPlayer.CustomCareerWickets = Convert.ToInt16(xmlReader.GetAttribute("Wickets"));
                                                                        tmpPlayer.CustomCareerFiveWicketHaul = Convert.ToInt16(xmlReader.GetAttribute("FiveWickets"));
                                                                        tmpPlayer.CustomCareerTenWicketHaul = Convert.ToInt16(xmlReader.GetAttribute("TenWickets"));
                                                                        tmpPlayer.CustomCareerBestBowlingFigue = Convert.ToDecimal(xmlReader.GetAttribute("BestBowling"));
                                                                        tmpPlayer.CustomCareerBowlingAvg = Convert.ToDecimal(xmlReader.GetAttribute("CareerBowlingAvg"));
                                                                        tmpPlayer.CustomCareerBowlingSR = Convert.ToDecimal(xmlReader.GetAttribute("CareerBowlingSR"));
                                                                        tmpPlayer.CustomCareerCatches = Convert.ToInt16(xmlReader.GetAttribute("Catches"));
                                                                    }

                                                                    while (xmlReader.Read() && (xmlReader.Name != "DOMODI"))
                                                                    {
                                                                        break;
                                                                    }
                                                                    if (xmlReader.Name == "DOMODI" && xmlReader.NodeType == XmlNodeType.Element)
                                                                    {
                                                                        tmpPlayer.NumFirstClass5050Matches = Convert.ToInt16(xmlReader.GetAttribute("Matches"));
                                                                        tmpPlayer.NumFirstClass5050Innings = Convert.ToInt16(xmlReader.GetAttribute("Innings"));
                                                                        tmpPlayer.NumFirstClass5050NotOuts = Convert.ToInt16(xmlReader.GetAttribute("NotOut"));
                                                                        tmpPlayer.Domestic5050Ranking = Convert.ToInt16(xmlReader.GetAttribute("Ranking"));
                                                                        try
                                                                        {
                                                                            tmpPlayer.FirstDOM5050Match = Convert.ToDateTime(xmlReader.GetAttribute("FirstMatch"));
                                                                        }
                                                                        catch { }
                                                                        tmpPlayer.DOMODICareerRuns = Convert.ToInt16(xmlReader.GetAttribute("Runs"));
                                                                        tmpPlayer.DOMODICareerCenturies = Convert.ToInt16(xmlReader.GetAttribute("Centuries"));
                                                                        tmpPlayer.DOMODICareerHalfCenturies = Convert.ToInt16(xmlReader.GetAttribute("Fifties"));
                                                                        tmpPlayer.DOMODICareerHighestScore = Convert.ToInt16(xmlReader.GetAttribute("HS"));
                                                                        tmpPlayer.DOMODICareerBattingAvg = Convert.ToDecimal(xmlReader.GetAttribute("CareerAvg"));
                                                                        tmpPlayer.DOMODICareerBattingSR = Convert.ToDecimal(xmlReader.GetAttribute("CareerBattingSR"));
                                                                        tmpPlayer.DOMODICareerOversBowled = Convert.ToDecimal(xmlReader.GetAttribute("OversBowled"));
                                                                        tmpPlayer.DOMODICareerWickets = Convert.ToInt16(xmlReader.GetAttribute("Wickets"));
                                                                        tmpPlayer.DOMODICareerFiveWicketHaul = Convert.ToInt16(xmlReader.GetAttribute("FiveWickets"));
                                                                        tmpPlayer.DOMODICareerTenWicketHaul = Convert.ToInt16(xmlReader.GetAttribute("TenWickets"));
                                                                        tmpPlayer.DOMODICareerBestBowlingFigue = Convert.ToDecimal(xmlReader.GetAttribute("BestBowling"));
                                                                        tmpPlayer.DOMODICareerBowlingAvg = Convert.ToDecimal(xmlReader.GetAttribute("CareerBowlingAvg"));
                                                                        tmpPlayer.DOMODICareerBowlingSR = Convert.ToDecimal(xmlReader.GetAttribute("CareerBowlingSR"));
                                                                        tmpPlayer.DOMODICareerCatches = Convert.ToInt16(xmlReader.GetAttribute("Catches"));
                                                                    }

                                                                    while (xmlReader.Read() && (xmlReader.Name != "DOMT20"))
                                                                    {
                                                                        break;
                                                                    }
                                                                    if (xmlReader.Name == "DOMT20" && xmlReader.NodeType == XmlNodeType.Element)
                                                                    {
                                                                        tmpPlayer.NumFirstClassT20Matches = Convert.ToInt16(xmlReader.GetAttribute("Matches"));
                                                                        tmpPlayer.NumFirstClassT20Innings = Convert.ToInt16(xmlReader.GetAttribute("Innings"));
                                                                        tmpPlayer.NumFirstClassT20NotOuts = Convert.ToInt16(xmlReader.GetAttribute("NotOut"));
                                                                        tmpPlayer.DomesticT20Ranking = Convert.ToInt16(xmlReader.GetAttribute("Ranking"));
                                                                        try
                                                                        {
                                                                            tmpPlayer.FirstDOMT20Match = Convert.ToDateTime(xmlReader.GetAttribute("FirstMatch"));
                                                                        }
                                                                        catch { }
                                                                        tmpPlayer.DOMT20CareerRuns = Convert.ToInt16(xmlReader.GetAttribute("Runs"));
                                                                        tmpPlayer.DOMT20CareerCenturies = Convert.ToInt16(xmlReader.GetAttribute("Centuries"));
                                                                        tmpPlayer.DOMT20CareerHalfCenturies = Convert.ToInt16(xmlReader.GetAttribute("Fifties"));
                                                                        tmpPlayer.DOMT20CareerHighestScore = Convert.ToInt16(xmlReader.GetAttribute("HS"));
                                                                        tmpPlayer.DOMT20CareerBattingAvg = Convert.ToDecimal(xmlReader.GetAttribute("CareerAvg"));
                                                                        tmpPlayer.DOMT20CareerBattingSR = Convert.ToDecimal(xmlReader.GetAttribute("CareerBattingSR"));
                                                                        tmpPlayer.DOMT20CareerOversBowled = Convert.ToDecimal(xmlReader.GetAttribute("OversBowled"));
                                                                        tmpPlayer.DOMT20CareerWickets = Convert.ToInt16(xmlReader.GetAttribute("Wickets"));
                                                                        tmpPlayer.DOMT20CareerFiveWicketHaul = Convert.ToInt16(xmlReader.GetAttribute("FiveWickets"));
                                                                        tmpPlayer.DOMT20CareerTenWicketHaul = Convert.ToInt16(xmlReader.GetAttribute("TenWickets"));
                                                                        tmpPlayer.DOMT20CareerBestBowlingFigue = Convert.ToDecimal(xmlReader.GetAttribute("BestBowling"));
                                                                        tmpPlayer.DOMT20CareerBowlingAvg = Convert.ToDecimal(xmlReader.GetAttribute("CareerBowlingAvg"));
                                                                        tmpPlayer.DOMT20CareerBowlingSR = Convert.ToDecimal(xmlReader.GetAttribute("CareerBowlingSR"));
                                                                        tmpPlayer.DOMT20CareerCatches = Convert.ToInt16(xmlReader.GetAttribute("Catches"));
                                                                    }

                                                                    while (xmlReader.Read() && (xmlReader.Name != "STREET"))
                                                                    {
                                                                        break;
                                                                    }
                                                                    if (xmlReader.Name == "STREET" && xmlReader.NodeType == XmlNodeType.Element)
                                                                    {
                                                                        tmpPlayer.NumStreetMatches = Convert.ToInt16(xmlReader.GetAttribute("Matches"));
                                                                        tmpPlayer.NumStreetInnings = Convert.ToInt16(xmlReader.GetAttribute("Innings"));
                                                                        tmpPlayer.NumStreetNotOuts = Convert.ToInt16(xmlReader.GetAttribute("NotOut"));
                                                                        tmpPlayer.StreetRanking = Convert.ToInt16(xmlReader.GetAttribute("Ranking"));
                                                                        try
                                                                        {
                                                                            tmpPlayer.FirstStreetMatch = Convert.ToDateTime(xmlReader.GetAttribute("FirstMatch"));
                                                                        }
                                                                        catch { }
                                                                        tmpPlayer.StreetCareerRuns = Convert.ToInt16(xmlReader.GetAttribute("Runs"));
                                                                        tmpPlayer.StreetCareerCenturies = Convert.ToInt16(xmlReader.GetAttribute("Centuries"));
                                                                        tmpPlayer.StreetCareerHalfCenturies = Convert.ToInt16(xmlReader.GetAttribute("Fifties"));
                                                                        tmpPlayer.StreetCareerHighestScore = Convert.ToInt16(xmlReader.GetAttribute("HS"));
                                                                        tmpPlayer.StreetCareerBattingAvg = Convert.ToDecimal(xmlReader.GetAttribute("CareerAvg"));
                                                                        tmpPlayer.StreetCareerBattingSR = Convert.ToDecimal(xmlReader.GetAttribute("CareerBattingSR"));
                                                                        tmpPlayer.StreetCareerOversBowled = Convert.ToDecimal(xmlReader.GetAttribute("OversBowled"));
                                                                        tmpPlayer.StreetCareerWickets = Convert.ToInt16(xmlReader.GetAttribute("Wickets"));
                                                                        tmpPlayer.StreetCareerFiveWicketHaul = Convert.ToInt16(xmlReader.GetAttribute("FiveWickets"));
                                                                        tmpPlayer.StreetCareerTenWicketHaul = Convert.ToInt16(xmlReader.GetAttribute("TenWickets"));
                                                                        tmpPlayer.StreetCareerBestBowlingFigue = Convert.ToDecimal(xmlReader.GetAttribute("BestBowling"));
                                                                        tmpPlayer.StreetCareerBowlingAvg = Convert.ToDecimal(xmlReader.GetAttribute("CareerBowlingAvg"));
                                                                        tmpPlayer.StreetCareerBowlingSR = Convert.ToDecimal(xmlReader.GetAttribute("CareerBowlingSR"));
                                                                        tmpPlayer.StreetCareerCatches = Convert.ToInt16(xmlReader.GetAttribute("Catches"));
                                                                    }

                                                                    while (xmlReader.Read() && (xmlReader.Name != "PARK"))
                                                                    {
                                                                        break;
                                                                    }
                                                                    if (xmlReader.Name == "PARK" && xmlReader.NodeType == XmlNodeType.Element)
                                                                    {
                                                                        tmpPlayer.NumParkMatches = Convert.ToInt16(xmlReader.GetAttribute("Matches"));
                                                                        tmpPlayer.NumParkInnings = Convert.ToInt16(xmlReader.GetAttribute("Innings"));
                                                                        tmpPlayer.NumParkNotOuts = Convert.ToInt16(xmlReader.GetAttribute("NotOut"));
                                                                        tmpPlayer.ParkRanking = Convert.ToInt16(xmlReader.GetAttribute("Ranking"));
                                                                        try
                                                                        {
                                                                            tmpPlayer.FirstParkmatch = Convert.ToDateTime(xmlReader.GetAttribute("FirstMatch"));
                                                                        }
                                                                        catch { }
                                                                        tmpPlayer.ParkCareerRuns = Convert.ToInt16(xmlReader.GetAttribute("Runs"));
                                                                        tmpPlayer.ParkCareerCenturies = Convert.ToInt16(xmlReader.GetAttribute("Centuries"));
                                                                        tmpPlayer.ParkCareerHalfCenturies = Convert.ToInt16(xmlReader.GetAttribute("Fifties"));
                                                                        tmpPlayer.ParkCareerHighestScore = Convert.ToInt16(xmlReader.GetAttribute("HS"));
                                                                        tmpPlayer.ParkCareerBattingAvg = Convert.ToDecimal(xmlReader.GetAttribute("CareerAvg"));
                                                                        tmpPlayer.ParkCareerBattingSR = Convert.ToDecimal(xmlReader.GetAttribute("CareerBattingSR"));
                                                                        tmpPlayer.ParkCareerOversBowled = Convert.ToDecimal(xmlReader.GetAttribute("OversBowled"));
                                                                        tmpPlayer.ParkCareerWickets = Convert.ToInt16(xmlReader.GetAttribute("Wickets"));
                                                                        tmpPlayer.ParkCareerFiveWicketHaul = Convert.ToInt16(xmlReader.GetAttribute("FiveWickets"));
                                                                        tmpPlayer.ParkCareerTenWicketHaul = Convert.ToInt16(xmlReader.GetAttribute("TenWickets"));
                                                                        tmpPlayer.ParkCareerBestBowlingFigue = Convert.ToDecimal(xmlReader.GetAttribute("BestBowling"));
                                                                        tmpPlayer.ParkCareerBowlingAvg = Convert.ToDecimal(xmlReader.GetAttribute("CareerBowlingAvg"));
                                                                        tmpPlayer.ParkCareerBowlingSR = Convert.ToDecimal(xmlReader.GetAttribute("CareerBowlingSR"));
                                                                        tmpPlayer.ParkCareerCatches = Convert.ToInt16(xmlReader.GetAttribute("Catches"));
                                                                    }

                                                                    while (xmlReader.Read() && (xmlReader.Name != "FINED"))
                                                                    {
                                                                        break;
                                                                    }
                                                                    if (xmlReader.Name == "FINED" && xmlReader.NodeType == XmlNodeType.Element)
                                                                    {
                                                                        tmpPlayer.Fined = Convert.ToInt16(xmlReader.GetAttribute("value"));
                                                                        _team.players.Add(tmpPlayer);
                                                                        break;
                                                                    }

                                                                }

                                                            }                                                            
                                                        }
                                                        
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        break;
                }
            }
        }

        /// <summary>
        /// Loads the team from XML.
        /// </summary>
        /// <param name="TeamID">The team ID.</param>
        public void LoadTeamFromXML(int TeamID)
        {
            XmlTextReader xmlReader;
            xmlReader = new XmlTextReader(@"22yardsContent\Core\Teams\Teams.xml");

            while (xmlReader.Read())
            {
                switch (xmlReader.NodeType)
                {
                    case XmlNodeType.Element:
                        if (xmlReader.Name == "TEAM")
                        {
                            if (Convert.ToInt32(xmlReader.GetAttribute("ID")) != TeamID)
                                break;
                            else
                                TeamNumber = Convert.ToInt32(xmlReader.GetAttribute("ID"));

                            TeamName = xmlReader.GetAttribute("name");
                            NetMoney = Convert.ToDecimal(xmlReader.GetAttribute("netmoney"));
                            StatsUpdatable = Convert.ToBoolean(xmlReader.GetAttribute("isupdatable"));
                            TeamShortName = xmlReader.GetAttribute("shortname");

                            while(xmlReader.Read() && (xmlReader.Name != "TEAM" || xmlReader.NodeType != XmlNodeType.EndElement))
                            {
                                if (xmlReader.Name == "MATCHESPLAYED")
                                {
                                    while (xmlReader.Read() && (xmlReader.Name != "MATCHESPLAYED" || xmlReader.NodeType != XmlNodeType.EndElement))
                                    {
                                        if (xmlReader.Name == "TEST" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            TestMatchesPlayed = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "ODI" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            ODIMatchesPlayed = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "T20" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            T20MatchesPlayed = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "DOM5DAY" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            DOM5DAYMatchesPlayed = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "DOM4DAY" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            DOM4DAYMatchesPlayed = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "CUSTOM" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            CustomMatchesPlayed = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "DOMODI" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            DOMODIMatchesPlayed = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "DOMT20" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            DOMT20MatchesPlayed = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "STREET" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            StreetMatchesPlayed = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "PARK" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            ParkMatchesPlayed = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                    }
                                }


                                if (xmlReader.Name == "MATCHESWON")
                                {
                                    while (xmlReader.Read() && (xmlReader.Name != "MATCHESWON" || xmlReader.NodeType != XmlNodeType.EndElement))
                                    {
                                        if (xmlReader.Name == "TEST" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            TestMatchesWon = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "ODI" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            ODIMatchesWon = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "T20" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            T20MatchesWon = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "DOM5DAY" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            DOM5DAYMatchesWon = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "DOM4DAY" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            DOM4DAYMatchesWon = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }

                                        if (xmlReader.Name == "CUSTOM" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            CustomMatchesWon = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "DOMODI" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            DOMODIMatchesWon = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "DOMT20" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            DOMT20MatchesWon = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "STREET" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            StreetMatchesWon = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "PARK" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            ParkMatchesWon = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                    }
                                }


                                if (xmlReader.Name == "NORESULT")
                                {
                                    while (xmlReader.Read() && (xmlReader.Name != "NORESULT" || xmlReader.NodeType != XmlNodeType.EndElement))
                                    {
                                        if (xmlReader.Name == "TEST" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            TestMatchesNoResult = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "ODI" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            ODIMatchesNoResult = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "T20" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            T20MatchesNoResult = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "DOM5DAY" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            DOM5DAYMatchesNoResult = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "DOM4DAY" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            DOM4DAYMatchesNoResult = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "CUSTOM" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            CustomMatchesNoResult = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "DOMODI" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            DOMODIMatchesNoResult = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "DOMT20" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            DOMT20MatchesNoResult = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "STREET" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            StreetMatchesNoResult = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "PARK" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            ParkMatchesNoResult = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                    }
                                }

                                if (xmlReader.Name == "TIE")
                                {
                                    while (xmlReader.Read() && (xmlReader.Name != "TIE" || xmlReader.NodeType != XmlNodeType.EndElement))
                                    {
                                        if (xmlReader.Name == "TEST" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            TestMatchesTie = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "ODI" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            ODIMatchesTie = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "T20" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            T20MatchesTie = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "DOM5DAY" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            DOM5DAYMatchesTie = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "DOM4DAY" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            DOM4DAYMatchesTie = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "CUSTOM" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            CustomMatchesTie = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "DOMODI" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            DOMODIMatchesTie = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "DOMT20" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            DOMT20MatchesTie = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "STREET" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            StreetMatchesTie = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "PARK" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            ParkMatchesTie = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                    }
                                }

                                if (xmlReader.Name == "TOUNAMENTSWON")
                                {
                                    while (xmlReader.Read() && (xmlReader.Name != "TOURNAMENTSWON" || xmlReader.NodeType != XmlNodeType.EndElement))
                                    {
                                        if (xmlReader.Name == "TEST" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            TestMatchesTournamentsWon = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "ODI" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            ODIMatchesTournamentsWon = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "T20" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            T20MatchesTournamentsWon = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "DOM5DAY" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            DOM5DAYMatchesTournamentsWon = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "DOM4DAY" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            DOM4DAYMatchesTournamentsWon = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "CUSTOM" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            CustomMatchesTournamentsWon = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "DOMODI" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            DOMODIMatchesTournamentsWon = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "DOMT20" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            DOMT20MatchesTournamentsWon = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "STREET" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            StreetMatchesTournamentsWon = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                        if (xmlReader.Name == "PARK" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            ParkMatchesTournamentsWon = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                        }
                                    }
                                }

                                if (xmlReader.Name == "TESTRANKING" && xmlReader.NodeType == XmlNodeType.Element)
                                {
                                    TestRanking = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                }

                                if (xmlReader.Name == "ODIRANKING" && xmlReader.NodeType == XmlNodeType.Element)
                                {
                                    ODIRanking = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                }

                                if (xmlReader.Name == "T20RANKING" && xmlReader.NodeType == XmlNodeType.Element)
                                {
                                    T20Ranking = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                }

                                if (xmlReader.Name == "STREETRANKING" && xmlReader.NodeType == XmlNodeType.Element)
                                {
                                    StreetRanking = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                }
                                if (xmlReader.Name == "PARKRANKING" && xmlReader.NodeType == XmlNodeType.Element)
                                {
                                    ParkRanking = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                }
                                if (xmlReader.Name == "DOMESTICRANKING" && xmlReader.NodeType == XmlNodeType.Element)
                                {
                                    TestRanking = Convert.ToInt32(xmlReader.GetAttribute("value"));
                                }

                                if (xmlReader.Name == "UDRS" && xmlReader.NodeType == XmlNodeType.Element)
                                {
                                    UDRSReviewed = Convert.ToInt16(xmlReader.GetAttribute("reviewed"));
                                    UDRSSuccessful = Convert.ToInt16(xmlReader.GetAttribute("successful"));
                                }

                                if (xmlReader.Name == "FINED" && xmlReader.NodeType == XmlNodeType.Element)
                                {
                                    while (xmlReader.Read() && (xmlReader.Name != "FINED" || xmlReader.NodeType != XmlNodeType.EndElement))
                                    {
                                        if (xmlReader.Name == "SLOWOVERRATE" && xmlReader.NodeType == XmlNodeType.Element)
                                        {
                                            FinedSlowOverRate = Convert.ToInt16(xmlReader.GetAttribute("value"));
                                        }
                                    }
                                }
                            }

                        }
                        break;
                }
            }
        }

        public static List<int> GetTeamIDsBasedOnType(int typeID)
        {
            List<int> TeamIDs = new List<int>();
            XmlTextReader xmlReader = new XmlTextReader(@"22yardsContent\Core\Teams\Teams.xml");
            while (xmlReader.Read())
            {
                switch (xmlReader.NodeType)
                {
                    case XmlNodeType.Element:
                        if (xmlReader.Name == "TYPE")
                        {
                            string IDfromXML = xmlReader.GetAttribute("ID");
                            if (IDfromXML == typeID.ToString())
                            {
                                while (xmlReader.Read() && (xmlReader.Name != "TYPE" || xmlReader.NodeType != XmlNodeType.EndElement))
                                {
                                    if (xmlReader.NodeType == XmlNodeType.Element && xmlReader.Name == "TEAM")
                                    {
                                        TeamIDs.Add(Convert.ToInt32(xmlReader.GetAttribute("ID")));
                                    }
                                }
                            }
                        }
                        break;
                }
            }
            return TeamIDs;
        }

        //public Team()
        //{
        //    players = new List<cPlayer>();
        //}
        public bool initTeam()
        {
            try
            {
                players = new List<cPlayer>();
                //Code to fetch team members into team
            }
            catch(System.Exception)
            {
                players = null;
                return false;
            }
            return true;
        }

        //Should be called after loadPlayerinSquad is called
        public string markPlayerInPlaying11(cPlayer player)
        {
            if (players == null || player == null)
                return "Invalid Player or Players";

            if (players.Count < 15)
                return "Squad contains " + players.Count + " players. Please select 15 only";

            foreach (cPlayer cplr in players)
            {
                if (cplr == null)
                    return "Failure";

                if (cplr.PlayerID == player.PlayerID)
                {
                    cplr.InPlaying11 = true;
                    break;
                }

            }

            return "Success";
        }

        //Should be called after loadPlayerinSquad is called
        public string UnmarkPlayerInPlaying11(cPlayer player)
        {
            if (players == null || player == null)
                return "Invalid Player or Players";

            if (players.Count < 15)
                return "Squad contains " + players.Count + " players. Please select 15 only";

            foreach (cPlayer cplr in players)
            {
                if (cplr == null)
                    return "Failure";

                if (cplr.PlayerID == player.PlayerID)
                {
                    cplr.InPlaying11 = false;
                    break;
                }

            }

            return "Success";
        }

        public string markPlayerAsExtra(cPlayer player)
        {
            if (players == null || player == null)
                return "Invalid Player or Players";

            if (players.Count < 15)
                return "Squad contains " + players.Count + " players. Please select 15 players";

            foreach (cPlayer cplr in players)
            {
                if (cplr == null)
                    return "Failure";

                if (cplr.PlayerID == player.PlayerID)
                {
                    cplr.Is12thMan = true;
                    break;
                }

            }

            return "Success";
        }

        public string UnmarkPlayerAsExtra(cPlayer player)
        {
            if (players == null || player == null)
                return "Invalid Player or Players";

            if (players.Count < 15)
                return "Squad contains " + players.Count + " players. Please select 15 players";

            foreach (cPlayer cplr in players)
            {
                if (cplr == null)
                    return "Failure";

                if (cplr.PlayerID == player.PlayerID)
                {
                    cplr.Is12thMan = false;
                    break;
                }
            }
            return "Success";
        }

        public string markPlayerAsWicketKeeper(cPlayer player)
        {
            if (players == null || player == null)
                return "Invalid Player or Players";

            if (players.Count < 15)
                return "Squad contains " + players.Count + " players. Please select 15 players";

            foreach (cPlayer cplr in players)
            {
                if (cplr == null)
                    return "Failure";

                if (cplr.PlayerID == player.PlayerID)
                {
                    cplr.IsWicketKeeper = true;
                    break;
                }
            }
            return "Success";
        }

        public string UnmarkPlayerAsWicketKeeper(cPlayer player)
        {
            if (players == null || player == null)
                return "Invalid Player or Players";

            if (players.Count < 15)
                return "Squad contains " + players.Count + " players. Please select 15 players";

            foreach (cPlayer cplr in players)
            {
                if (cplr == null)
                    return "Failure";

                if (cplr.PlayerID == player.PlayerID)
                {
                    cplr.IsWicketKeeper = false;
                    break;
                }
            }
            return "Success";
        }

        public bool loadPlayerInSquad(cPlayer player) //Can load upto 15 players
        {
            if (player != null && players != null)
            {
                if (players.Count < 15)
                    players.Add(player);

                return true;
            }
            return false;

        }

        public bool removePlayerFromSquad(cPlayer player)
        {
            if (players != null && player != null)
            {
                foreach (cPlayer cplr in players)
                {
                    if (cplr == null)
                        return false;

                    if (cplr.PlayerID == player.PlayerID)
                    {
                        players.Remove(cplr);
                        break;
                    }

                }
                return true;
            }

            return false;
        }

        public short GetTeamCurrentBattingConfidence()
        {
            short iBatForm = 0;
            short ctr = 0;

            if (players == null)
                return -1;

            foreach (cPlayer cplr in players)
            {
                if (cplr == null)
                    return -1;
                if (cplr.InPlaying11)
                {
                    ctr++;
                    iBatForm += cplr.CurrentBattingConfidence;
                }
            }

            if (ctr == 0)
                return -1;

            return (short)(iBatForm / ctr);
        }

        public short GetTeamCurrentBowlingConfidence()
        {
            short iBowlForm = 0;
            short ctr = 0;

            if (players == null)
                return -1;

            foreach (cPlayer cplr in players)
            {
                if (cplr == null)
                    return -1;

                if (cplr.InPlaying11)
                {
                    ctr++;
                    iBowlForm += cplr.CurrentBowlingConfidence;
                }
            }

            if (ctr == 0)
                return -1;

            return (short)(iBowlForm/ctr);
        }

        public short GetTeamCurrentFieldingConfidence()
        {
            short iFieldForm = 0;
            short ctr = 0;

            if (players == null)
                return -1;

            foreach (cPlayer cplr in players)
            {
                if (cplr == null)
                    return -1;

                if (cplr.InPlaying11 || cplr.Is12thMan)
                {
                    ctr++;
                    iFieldForm += cplr.CurrentFieldingConfidence;
                }
            }

            if (ctr == 0)
                return -1;

            return (short)(iFieldForm / ctr);
        }

        public short GetTeamCurrentOverallForm()
        {
            return (short)((GetTeamCurrentBattingConfidence() + GetTeamCurrentBowlingConfidence() + GetTeamCurrentFieldingConfidence()) / 3);
        }

        public short GetTeamBattingPoints()
        {
            short iBatPoints = 0;
            short ctr = 0;

            if (players == null)
                return -1;
           
            foreach (cPlayer cplr in players)
            {
                if (cplr == null)
                    return -1;
                if (cplr.InPlaying11)
                {
                    ctr++;
                    iBatPoints += cplr.BattingSkillPoints;
                }
            }

            if (ctr == 0)
                return -1;

            return (short)(iBatPoints / ctr);
        }

        public short GetTeamBowlingPoints()
        {
            short iBowlPoints = 0;
            short ctr = 0;

            if (players == null)
                return -1;

            foreach (cPlayer cplr in players)
            {
                if (cplr == null)
                    return -1;
                if (cplr.InPlaying11)
                {
                    ctr++;
                    iBowlPoints += cplr.BowlingSkillPoints;
                }
            }

            if (ctr == 0)
                return -1;

            return (short)(iBowlPoints / ctr);
        }

        public short GetTeamFieldingPoints()
        {
            short iFieldPoints = 0;
            short ctr = 0;

            if (players == null)
                return -1;

            foreach (cPlayer cplr in players)
            {
                if (cplr == null)
                    return -1;

                if (cplr.InPlaying11 || cplr.Is12thMan)
                {
                    ctr++;
                    iFieldPoints += cplr.FieldingSkillPoints;
                }
            }

            if (ctr == 0)
                return -1;

            return (short)(iFieldPoints / ctr);
        }

        public short GetTeamOverallPoints()
        {
            return (short)((GetTeamBattingPoints() + GetTeamBowlingPoints() + GetTeamFieldingPoints()) / 3);
        }
    }
}
